package com.hps.activemq.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.hps.activemq.aq.Sender;
import com.hps.activemq.entity.Good;
import com.hps.activemq.entity.Order;
import com.hps.activemq.entity.User;
import com.hps.activemq.service.GoodService;
import com.hps.activemq.service.OrderService;
import com.hps.activemq.service.UserService;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author admin
 * @since 2019-01-11
 */
@RestController
@RequestMapping("/goods")
public class GoodController {

    private GoodService goodService;

    public GoodController(GoodService goodService) {
        this.goodService = goodService;
    }

    /**
     * 分页查询商品信息
     * @param page 当前页码
     * @param size 每页大小
     * @return 查询结果
     */
    @GetMapping
    public Page<Good> findByPage(Integer page, Integer size) {
        return goodService.selectPage(new Page<>(page, size));
    }

    @PostMapping
    public Good add(Good good) {
        goodService.insert(good);
        return good;
    }

    /**
     * 用户下单
     * @param userId 用户Id
     * @param goodId 商品Id
     * @return 下单结果
     */
    @GetMapping("/{userId}/{goodId}")
    public Map<String, Object> buy(@PathVariable Long userId, @PathVariable Long goodId) {
        return goodService.buy(userId, goodId);
    }
}

